﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace FirstGame
{
    public class My2Dsprite
    {
        private Vector2 _Size = new Vector2(0, 0);

        public Vector2 Size
        {
            get { return _Size; }
            set { _Size = value; }
        }

        private Texture2D[] _Textures;

        public Texture2D[] Textures
        {
            get { return _Textures; }
            set
            {
                _Textures = value;
                _nTexture = _Textures.Length;
                _iTexture = 0;
            }
        }
        private Vector2 _Position;

        public Vector2 Position
        {
            get { return _Position; }
            set { _Position = value; }
        }

        private int _nTexture;

        public int NTexture
        {
            get { return _nTexture; }
            set { _nTexture = value; }
        }
        private int _iTexture;

        public int ITexture
        {
            get { return _iTexture; }
            set { _iTexture = value; }
        }
        public My2Dsprite(Texture2D[] _textures, Vector2 _position)
        {
            Textures = _textures;
            Position = _position;
        }

        private float _NormalDelay = 16.0f;

        public float NormalDelay
        {
            get { return _NormalDelay; }
            set { _NormalDelay = value; }
        }

        public void Update(GameTime gameTime)
        {
            int detal = (int)(gameTime.TotalGameTime.Milliseconds / _NormalDelay);
            _iTexture = (detal) % _nTexture;
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch, byte Alpha)
        {

            Rectangle rect = new Rectangle();
            if (Size.X == 0)
                rect = new Rectangle((int)Position.X, (int)Position.Y, _Textures[_iTexture].Width, _Textures[_iTexture].Height);
            else
                rect = new Rectangle((int)Position.X, (int)Position.Y, (int)Size.X, (int)Size.Y);

            spriteBatch.Draw(_Textures[_iTexture], rect, new Color(255, 255, 255, Alpha));
        }
    }
}
